/* 
 *   Date       Developer   Description
 *   
 *
 *   Classname:  com.ytincl.scdp.scdk.db.utils.DropAllTable
 * 
 *   Date:   2009-8-21
 * 
 *   The source code contained in this listing is proprietary to
 *   HLJ POST YITONG INFO-NET CO.,LTD.
 * 
 *   Unauthorized copying, adaptation, distribution, use, or display
 *   is strictly prohibited.
 *   This software is Copyright 2009 HLJ POST YITONG INFO-NET CO.,LTD.
 */
package demo.database;

import java.sql.Connection;

import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.db.RecordSet;

/**
 *
 *
 * @author 周成功
 *
 */
public class DropAllTable {
    public static void main(String[] args) {
        String[][] config = new String[][] {
                {"127.0.0.1", "1521", "ORCL", "ewms3_scdp", "ewms3_scdp"},
                {"127.0.0.1", "1521", "ORCL", "ewms3", "ewms3"}
        };
        
        Connection conn = null;
        try {
            String sqlAllTable = "select t.tname from tab t where t.tabtype='TABLE' and tname not in (SELECT object_name FROM user_recyclebin)";

            for (int i = 0; i < config.length; i++) {
                conn = DBUtils.getOracleConnection(config[i][0], config[i][1], config[i][2], config[i][3], config[i][4], true);
                RecordSet record = DBUtils.executeQueryToRecordSet(conn, sqlAllTable);
                while(record.moveNext()) {
                    String tablename = record.getString("tname");
                    String sql = "drop table " + tablename + "  cascade constraints";
//                    System.out.println("sql="+sql);
                    DBUtils.execute(conn, sql);
                }
                DBUtils.close(conn);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DBUtils.close(conn);
        }
    }
}

